package demo;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.AbstractAction;

import java.awt.event.ActionEvent;

import javax.swing.Action;

import java.awt.event.ActionListener;

/**
 * swing+逻辑实现
 * showConfirmDialog(panel,message,tip,JOptionPanel.DEFAULT_OPTION)
 */
public class B_19 extends JFrame {

	private JPanel contentPane;
	private JTextField name;
	private JTextField password;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					B_19 frame = new B_19();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public B_19() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("用户名:");
		lblNewLabel.setBounds(39, 35, 72, 18);
		contentPane.add(lblNewLabel);
		
		JLabel label = new JLabel("密码:");
		label.setBounds(39, 79, 72, 18);
		contentPane.add(label);
		
		name = new JTextField();
		name.setBounds(113, 32, 167, 24);
		contentPane.add(name);
		name.setColumns(10);
		
		password = new JTextField();
		password.setBounds(113, 76, 167, 24);
		contentPane.add(password);
		password.setColumns(10);
		
		JButton button = new JButton("确认");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String nameStr = name.getText();
				String passwordStr = password.getText();
				if("19".equals(nameStr) && "1234".equals(passwordStr)){
					int i = JOptionPane.showConfirmDialog(contentPane, "登录成功", "提示ʾ", JOptionPane.DEFAULT_OPTION);
					System.out.println(i);
					System.exit(-1);
				}else{
					int i = JOptionPane.showConfirmDialog(contentPane, "不存在该用户或密码错误","提示",JOptionPane.DEFAULT_OPTION);
					System.out.println(i);
					if(i == 0) {
						name.setText("");
						password.setText("");
					}
				}
				System.out.println(name.getText()+" "+password.getText());
			}
		});
		button.setBounds(39, 148, 113, 27);
		contentPane.add(button);
	}
	
}
